<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
	<link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>

<div id="updateCommodityDiv">
	<form class="layui-form" id="editCustomer" lay-filter="editCustomer">
		<div class="layui-panel">
			<div class="layui-form-item">
				<label class="layui-form-label">商品编号:</label>
				<div class="layui-input-inline">
					<input type="text" name="proId" autocomplete="off" readonly="" class="layui-input"
						   style="border:none; outline:medium;">
				</div>

				<label class="layui-form-label">商品名称:</label>
				<div class="layui-input-inline">
					<input type="text" name="proName" autocomplete="off" readonly="" class="layui-input"
						   style="border:none; outline:medium;">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">规格型号:</label>
				<div class="layui-input-inline">
					<input type="text" name="proSize" autocomplete="off" readonly="" class="layui-input"
						   style="border:none;">
				</div>
				<label class="layui-form-label">单位:</label>
				<div class="layui-input-inline">
					<input type="text" name="unitName" autocomplete="off" readonly="" class="layui-input"
						   style="border:none; outline:medium;">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">当前库存:</label>
				<div class="layui-input-inline">
					<input type="text" name="inveDescInventoryNum" autocomplete="off" readonly=""
						   class="layui-input" style="border:none; outline:medium;">
				</div>
				<label class="layui-form-label">批准文号:</label>
				<div class="layui-input-inline">
					<input type="text" name="proPostil" autocomplete="off" readonly="" class="layui-input"
						   style="border:none; outline:medium;">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">生产厂商:</label>
				<div class="layui-input-inline">
					<input type="text" name="manufacturerName" autocomplete="off" readonly=""
						   class="layui-input" style="border:none; outline:medium;">
				</div>
				<label class="layui-form-label">备注:</label>
				<div class="layui-input-inline">
					<input type="text" name="proComment" autocomplete="off" readonly="" class="layui-input"
						   style="border:none; outline:medium;">
				</div>
			</div>
		</div>
		<div class="layui-panel">
			<div class="layui-form-item">
				<label class="layui-form-label">参考进价:</label>
				<div class="layui-input-inline">
					<input type="text" name="proBid" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label">数量:</label>
				<div class="layui-input-inline">
					<input type="text" name="purStoDescNum" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">产品批号:</label>
				<div class="layui-input-inline">
					<input type="text" name="inveDescBatchNum" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label">总金额:</label>
				<div class="layui-input-inline">
					<input type="text" name="totalMoney" readonly autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item" style="display: none;">
				<input type="txt" name="proSalePrice" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">生产日期:</label>
				<div class="layui-input-inline">
					<input type="txt" name="inveDescStartDate" id="productionDate" autocomplete="off"
						   class="layui-input">
				</div>
				<label class="layui-form-label">有效期至:</label>
				<div class="layui-input-inline">
					<input type="txt" name="inveDescValidityDate" id="effectiveDate" autocomplete="off"
						   class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<input type="txt" name="inveDescComment" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="text-align: center;">
				<button class="layui-btn layui-btn-sm" lay-submit lay-filter="btn">确定</button>
			</div>
		</div>

	</form>
	<div class="layui-panel">
		<fieldset class="tatable-search-fieldset" style="border:1px solid #eee;">

			<legend>采购历史</legend>
			<div> 该商品采购进货历史</div>
			<table class="layui-hide" id="purchaseHistory" lay-filter="purchaseHistory"></table>
		</fieldset>
	</div>
</div>

<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
	<script>
		layui.use(['form', 'table', 'layer', 'tree', 'tableSelect'], function() {
			var $ = layui.jquery,
				form = layui.form,
				table = layui.table,
				layer = layui.layer,
				tableSelect = layui.tableSelect,
				tree = layui.tree;
			var laydate = layui.laydate;


			//历史进货
			table.render({
				elem: '#purchaseHistory	',
				url: '	',
				cols: [
					[{
						field: 'id',
						width: 80,
						title: 'ID',
						sort: true
					},
						{
							field: 'username',
							width: 80,
							title: '用户名'
						},
						{
							field: 'sex',
							width: 80,
							title: '性别',
							sort: true
						},
						{
							field: 'city',
							width: 80,
							title: '城市'
						},
						{
							field: 'sign',
							title: '签名',
							minWidth: 150
						},
						{
							field: 'experience',
							width: 80,
							title: '积分',
							sort: true
						},
						{
							field: 'score',
							width: 80,
							title: '评分',
							sort: true
						},
						{
							field: 'classify',
							width: 80,
							title: '职业'
						}
					]
				],
				limits: [10, 15, 20, 25, 50, 100],
				limit: 15,
				page: true,
				skin: 'line'
			});


			if((parent.ifproductInfo == 'leftProduct'||parent.ifproductInfo=='leftrecentStock'){
                //时间控件
                laydate.render({
                    elem: '#productionDate',
                    value: new Date(),
                    isInitValue: true,
                });
                //时间控件
                laydate.render({
                    elem: '#effectiveDate',
                    value: new Date(),
                    isInitValue: true,
                });
			}

			//获取父页面商品信息(String对象 --> JSON格式的对象)
			var dataobj = JSON.parse(parent.purchaseDetailsInfo);
            var s =$("input[name=purStoDescNum]").val(1)
			if (parent.ifproductInfo == 'leftProduct') {
                var proId = dataobj.proId;
                var myDate = new Date();
                var year = myDate.getYear(); //获取当前年
                var year = year < 2000 ? year + 1900 : year//计算2000后的具体年份
                var year = year.toString().substr(2, 2);//截取年份后两位
                var mon = myDate.getMonth() + 1; //获取当前月
                var date = myDate.getDate();
                if (mon<10){
                    mon ='0'+mon;
                }
                if (date<10){
                    date ='0'+date;
                }
                var purStoDate =(year+'-'+mon+'-'+date);
				var purchaseBatchNum=(year+mon+date);

                //产品批号
                $.ajax({
                    url: '/searchProBatchNum/'+ proId + "/" + purStoDate,
                    dataType:'json',
                    type: 'get',
                    success: function(data) {

                        if (data!=proId) {
                            $("input[name=inveDescBatchNum]").val(parseInt(data) + 1);
                        }else {
                            $("input[name=inveDescBatchNum]").val(purchaseBatchNum+'01');
						}
                    }
                });


				// 取出数据中第二层数据渲染给页面元素
				$("input[name=unitName]").val(dataobj.productUnit.unitName);

				if (null == dataobj.inventoryDesc) {
					$("input[name=inveDescInventoryNum]").val(0);
				} else {
					$("input[name=inveDescInventoryNum]").val(dataobj.inventoryDesc.inveDescInventoryNum);
				}
				$("input[name=manufacturerName]").val(dataobj.manufactureridInfo.manufacturerName);

			} else if (parent.ifproductInfo == 'rightProduct' || parent.ifproductInfo == 'centerProduct') {
				$("input[name=proBid]").attr("readOnly", true)
				$("input[name=inveDescBatchNum]").attr("readOnly", true)
				$("input[name=inveDescStartDate]").attr("readOnly", true)
				$("input[name=inveDescValidityDate]").attr("readOnly", true)


			}else if (parent.ifproductInfo=='leftrecentStock'){
				//规格
                $("input[name=inveDescBatchNum]").val(dataobj.proBatchNum)
				//产品批号
              	$("input[name=proSize]").val(dataobj.purchaseSize)
				//单位
                $("input[name=unitName]").val(dataobj.purStoDescUnit)
				//库存
                $("input[name=inveDescInventoryNum]").val(dataobj.inventoryDesc.inveDescInventoryNum)
				//批准文号
                $("input[name=proPostil]").val(dataobj.purPostil)
				//生产厂商
                $("input[name=manufacturerName]").val(dataobj.purStoDescManufacturer)
				//参考进价
                $("input[name=proBid]").val(dataobj.purStoDescPrice)
				//生产日期
                $("input[name=inveDescStartDate]").val(dataobj.purStoDescStartDate)
				//有效期
                $("input[name=inveDescValidityDate]").val(layui.util.toDateString(dataobj.purchaseProValidityDate, 'yyyy-MM-dd'))
				var s = parseInt($("input[name=purStoDescNum]").val())

                $("input[name=totalMoney]").val(parseInt($("input[name=proBid]").val()) *s)
			}

            form.val('editCustomer', dataobj);
			//5.总金额自动计算
			//进价
			var buyPrice = $("input[name=proBid]");
			//数量
			var buyNum = $("input[name=purStoDescNum]").val(1);
			//按键被松开时触发
			buyPrice.on('keyup', function() {

                if (isNaN($(this).val())){
                    layer.msg('请输入正确的数字！', {
                        time: 700
                    })
                    $(this).val(0);
                }

				checkNum($(this).val());
			});

			buyNum.on('keyup', function() {
				buyNum.val($(this).val());
				if (isNaN($(this).val())){
                    layer.msg('请输入正确的数字！', {
                        time: 700
                    })
				}
				checkNum($(this).val());
			});

			//限制input只能输入数字和两位小数
			function checkNum(num) {
				var isNum = isNaN(num);
				if (!isNum) {
					$("input[name=totalMoney]").val
					(+buyPrice.val() * +buyNum.val()) //总金额
				}
			}


			//表单提交按钮
			form.on('submit(btn)', function(data) {
				var Iflag = true;
				//tableContent用来保存表单数据
				tableContent = JSON.parse(JSON.stringify(data.field));
				//区分数据
				var lsArray = parent.tableContents;
				//区分重载页面
				var pages = 'chooseProductsId';
				//给tableContents表格实例集合追加赋值

				if (parent.ifproductInfo == 'centerProduct') {
					pages = 'currentTableId';
					lsArray = parent.currentTableList;
				}

				for (var i = 0, len = lsArray.length; i < len; i++) {
					if (lsArray[i].proId == tableContent.proId && lsArray[i].inveDescBatchNum == tableContent
							.inveDescBatchNum &&lsArray[i].proBid==tableContent.proBid) {
						if (parent.ifproductInfo == 'leftProduct') {
							lsArray[i].purStoDescNum = parseInt(lsArray[i].purStoDescNum) + parseInt(
								tableContent.purStoDescNum);
						} else {
							lsArray[i].purStoDescNum = parseInt(tableContent.purStoDescNum);
						}
						lsArray[i].totalMoney = lsArray[i].purStoDescNum * lsArray[i].proBid;
						Iflag = false;
						break;
					}
				}

				if (Iflag) {
					lsArray.push(tableContent);
				}

				parent.layui.table.reload(pages, {
					//填充data属性
					data: lsArray
				})
				//关闭子页面
				var iframeIndex = parent.layer.getFrameIndex(window.name);
				parent.layer.close(iframeIndex);
			})

		})
</script>


</body>
</html>
